package usr;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import page.PageState;


public class UsrLogin extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		

		Usr usr = new Usr();
		usr.setLogin(req.getParameter("login"));
		usr.setPassword(req.getParameter("password"));
		
		int i = usr.login();
		
		if ( i != PageState.SUCCESSFUL ) {
			req.setAttribute("error_cause", i);
			req.getRequestDispatcher("login.jsp").forward(req, resp);
				
		} else {
			HttpSession session = req.getSession();
			session.setAttribute("usr", usr);
			resp.sendRedirect("dashboard.jsp"); // dashboard.jsp
		}
		
	}

}
	

